package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.AnNideshopGood;
import com.example.demo.entity.DTO.GoodsNewDTO;
import com.example.demo.mapper.AnNideshopGoodMapper;
import com.example.demo.service.IAnNideshopGoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 首页商品表 服务实现类
 * </p>
 *
 * @author Mr.We
 * @since 2024-06-20
 */
@Service
public class AnNideshopGoodServiceImpl extends ServiceImpl<AnNideshopGoodMapper, GoodsNewDTO> implements IAnNideshopGoodService {
    @Resource
    private AnNideshopGoodMapper anNideshopGoodMapper;

    @Override
    public GoodsNewDTO queryGoodsById(Integer id) {
        return anNideshopGoodMapper.selectById(id);
    }

    @Override
    public List<GoodsNewDTO> queryList(Map<String, Object> map) {
        QueryWrapper<GoodsNewDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", map.get("isDelete"))
                .eq("is_on_sale", map.get("isOnSale"));
        return anNideshopGoodMapper.selectList(queryWrapper);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        List<GoodsNewDTO> anNideshopGoods = anNideshopGoodMapper.selectByMap(map);
        if (!anNideshopGoods.isEmpty()){
            return 1;
        }
        return -1;
    }

    @Override
    public List<GoodsNewDTO> queryHotGoodsList(Map<String, Object> map) {
        return anNideshopGoodMapper.queryHotGoodsList(map);
    }

    @Override
    public List<GoodsNewDTO> queryCatalogProductList(Map<String, Object> map) {
        return anNideshopGoodMapper.queryCatalogProductList(map);
    }

    @Override
    public boolean save(GoodsNewDTO goods) {
        if (goods.getId() == null){
            anNideshopGoodMapper.save(goods);
            return true;
        }
        return false;
    }


    public void update(GoodsNewDTO goods) {
        QueryWrapper<GoodsNewDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", goods.getId());
        anNideshopGoodMapper.update(queryWrapper);
    }


    public void delete(Integer id) {
        QueryWrapper<GoodsNewDTO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        anNideshopGoodMapper.delete(queryWrapper);
    }


    public void deleteBatch(Integer[] ids) {
        anNideshopGoodMapper.deleteBatch(ids);
    }
}
